﻿using System.Diagnostics;
using System.Net.NetworkInformation;

namespace NetwordEnabler
{
    public class NetworkEnabler
    {
        public static void Enable(string name)
        {
            Process cmd = new Process();
            ProcessStartInfo si = new ProcessStartInfo();

            si.FileName = "cmd.exe";
            si.Verb = "runas";
            si.Arguments = "/env /user: Administrator cmd /C netsh interface set interface \"" + name + "\" ENABLE";
            si.UseShellExecute = true;
            si.CreateNoWindow = true;

            cmd.StartInfo = si;
            cmd.Start();
        }

        public static void Disable(string name)
        {
            Process cmd = new Process();
            ProcessStartInfo si = new ProcessStartInfo();

            si.FileName = "cmd.exe";
            si.Verb = "runas";
            si.Arguments = "/env /user: Administrator cmd /C netsh interface set interface \"" + name + "\" DISABLE";
            si.UseShellExecute = true;
            si.CreateNoWindow = true;

            cmd.StartInfo = si;
            cmd.Start();
        }

        public static bool Check(string name)
        {
            NetworkInterface[] interfaces = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces();
            OperationalStatus os = OperationalStatus.Unknown;

            foreach(NetworkInterface i in interfaces)
            {
                if (i.Name.Equals(name))
                {
                    os = i.OperationalStatus;
                    break;
                }
            }
            Debug.WriteLine(os.ToString());
            if (os == OperationalStatus.Up) return true;
            return false;
        }
    }
}
